--低汇高卖
local dihuigaomai = fk.CreateSkill {
    name = "mcdh_dihuigaomai"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

dihuigaomai:addEffect('active',{
    target_num = 1,
    can_use = function(self, player)
        if #player:getCardIds("e") ~= 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 then
            local alive_players = Fk:currentRoom().alive_players
            for _, p in pairs(alive_players) do
                if player:canMoveCardsInBoardTo(p,"e") then return true end
            end
        end
    end,
    card_filter = function(self, to_select, selected, targets)
        return false
    end,
    target_filter = function(self,player, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local  targets = table.filter(room.alive_players,function(p) return player:canMoveCardsInBoardTo(p,"e") end)
        local to = room:askToChoosePlayers(target, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "#dihuigaomai:" .. player.id,
            skill_name = self.name,
            cancelable = false
        })[1]
        room:askToMoveCardInBoard(target,{target_one=player,target_two=to,skill_name=self.name,flag="e",move_from=player})
        local  num = #target:getCardIds("e")
        local cards =room:askForCard(target, num, num, true, self.name, false, ".", "#dihuigaomai-give:"..player.id.."::"..num)
        room:moveCardTo(cards, Player.Hand, player, fk.ReasonGive, self.name, nil, false, target)
    end,
})

Fk:loadTranslationTable {
    ["mcdh_dihuigaomai"] = "低汇高卖",
    [":mcdh_dihuigaomai"] = "出牌阶段限一次，你可以令一名其他角色移动你装备区内的一张牌，然后其交给你X张牌。（X为其装备区内的牌数）",
    ["#dihuigaomai"] = "低汇高卖: 将 %src 的一张装备移至一名角色的装备区",
    ["#dihuigaomai-give"] = "低汇高卖: 交给 %src %arg 张牌"
}

return dihuigaomai